package com.example.mvvmdemo.data.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.blankj.utilcode.util.Utils
import com.example.mvvmdemo.data.db.dao.HomeDao
import com.example.mvvmdemo.data.entity.BannerBean
import com.example.mvvmdemo.data.entity.HomeListBean

/**
 *   @auther : yangk
 *   time   : 2021/11/15
 */
@Database(entities = [HomeListBean::class, BannerBean::class], version = 1, exportSchema = false)
abstract class IDatabase : RoomDatabase() {

    abstract fun homeLocaData(): HomeDao


    companion object {
        fun getInstanse() = SingletonHolder.INSTANCE
    }

    private object SingletonHolder {
        val INSTANCE = Room.databaseBuilder(
            Utils.getApp(),
            IDatabase::class.java,
            "mvvmdemo_db"
        )
            //清除源数据库数据
            .fallbackToDestructiveMigration()
            .build()
    }
    // .addMigrations(MIGRATION.MIGRATION_1_2)
}